//
//  TheNewMusicCollectionViewCell.m
//  NewMusic
//
//  Created by dllo on 15/11/15.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "TheNewMusicCollectionViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
@interface TheNewMusicCollectionViewCell ()
//背景图
@property(nonatomic, retain) UIView *backView;
//图片
@property(nonatomic, retain) UIImageView *picUrlImageView;
//歌名
@property(nonatomic, retain) UILabel *nameLabel;
//歌手名字
@property(nonatomic, retain) UILabel *singerNameLabel;
@end
@implementation TheNewMusicCollectionViewCell
- (void)dealloc {
    [_backView release];
    [_moreNewSongsModel release];
    [_picUrlImageView release];
    [_nameLabel release];
    [_singerNameLabel release];
    [super dealloc];
    
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        //创建视图
        [self createSubView];
    }
    return self;
}
#pragma mark 创建视图
-(void)createSubView {
    //背景图片
    self.backView = [[UIView alloc]init];
    self.backView.backgroundColor = [UIColor whiteColor];
    self.backView.alpha = 0.05;
    [self.contentView addSubview:self.backView];
    [self.backView release];
   //图片
    self.picUrlImageView = [[UIImageView alloc]init];
//    self.picUrlImageView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.picUrlImageView];
    [self.picUrlImageView release];
    
    //歌名
    self.nameLabel = [[UILabel alloc]init];
//    self.nameLabel.backgroundColor = [UIColor cyanColor];
    self.nameLabel.font = [UIFont systemFontOfSize:18];
    self.nameLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel release];
    
    //歌手名
    self.singerNameLabel = [[UILabel alloc]init];
//    self.singerNameLabel.backgroundColor = [UIColor purpleColor];
    self.singerNameLabel.font = [UIFont systemFontOfSize:14];
    self.singerNameLabel.textColor = [UIColor colorWithRed:0.639 green:0.663 blue:0.694 alpha:1.000];
    [self.contentView addSubview:self.singerNameLabel];
    [self.singerNameLabel release];
}
#pragma mark 设置大小
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    //背景图片
    self.backView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    //图片
    self.picUrlImageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 45);
    //歌名
    self.nameLabel.frame = CGRectMake(0, self.picUrlImageView.frame.size.height, self.frame.size.width, 25);
    //歌手名
    self.singerNameLabel.frame = CGRectMake(0, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height, self.frame.size.width, 15);
}
#pragma mark 重写moreNewSongsModel的setter方法
- (void)setMoreNewSongsModel:(MoreNewSongsModel *)moreNewSongsModel {
    if (_moreNewSongsModel != moreNewSongsModel) {
        [_moreNewSongsModel release];
        _moreNewSongsModel = [moreNewSongsModel retain];
    }
    //图片
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:moreNewSongsModel.picUrl]];
    //歌名
    self.nameLabel.text = moreNewSongsModel.name;
    //歌手名
    self.singerNameLabel.text = moreNewSongsModel.singerName;
}
@end
